﻿using System;
using System.Collections.Generic;
using System.Text;
using Dapper;
using UserCenter.Models;

namespace UserCenter.BLL
{
    public class WxLoginInfoBLL
    {
        public static bool Exists(string openId)
        {
            using (var conn = DatabaseHelper.Get())
            {
                return conn.QuerySingleOrDefault<int>("SELECT COUNT(1) from wx_login_info where OpenId=@OpenId", new { OpenId = openId }) > 0;
            }
        }

        public static bool Insert(WxLoginInfo info)
        {
            using (var conn = DatabaseHelper.Get())
            {
                return conn.Execute(@"INSERT INTO wx_login_info (`OpenId`,`MemberId`,`AppId`,`Unionid`,`NickName`,`Sex`,`Province`,`City`,`Country`,`HeadImgUrl`,`Privilege`,`CreateTime`)
                                    VALUES (@OpenId,@MemberId,@AppId,@Unionid,@NickName,@Sex,@Province,@City,@Country,@HeadImgUrl,@Privilege,@CreateTime)", info) > 0;
            }
        }

        public static WxLoginInfo Info(string unionId)
        {
            using (var conn = DatabaseHelper.Get())
            {
                return conn.QuerySingleOrDefault<WxLoginInfo>("SELECT * from wx_login_info where UnionId=@UnionId", new { UnionId = unionId });
            }
        }


    }
}
